import json
import re
import requests

url = "https://toolbar.suning.com//api/jsonp/cb/homepagev8-homepagev8.jsonp"
params = {
    "callback": "homepagev8"
}
response = requests.get(url, params=params)
result = response.content.decode()


def extract_homepagev8(result):
    pattern = r'homepagev8\((.*?)\)'
    matches = []
    for match in re.finditer(pattern, result):
        start = match.start(0) + len('homepagev8(')
        count = 1  # 括号深度计数
        for i in range(start, len(result)):
            if result[i] == '(':
                count += 1
            elif result[i] == ')':
                count -= 1

            if count == 0:  # 找到匹配
                matches.append(result[match.start(0):i + 1])
                break
    return matches


result_string = extract_homepagev8(result)[0][len('homepagev8('):-1]
# print(result_string)
result = json.loads(result_string)
# print(result, type(result))
for category in result[1]['header_mulu']['nodes']:
    print(category)
    for detail_category in category['nodes'][0]['tag']:
        print(detail_category['elementName'],detail_category['modelFullId'],detail_category['templateFullId'])


